package com.code.demo.mvp.presenter;

import android.util.Log;

import com.code.demo.mvp.base.BaseMvpPresenter;
import com.code.demo.mvp.base.OkgoStringCallback;
import com.code.demo.mvp.contract.FakeContract;
import com.code.demo.mvp.model.FakeModel;
import com.lzy.okgo.model.Response;
import com.lzy.okgo.request.base.Request;

/**
 * Created by yangliguo on 2019/3/1.
 */

public class FakePresenter extends BaseMvpPresenter<FakeContract.FakeView> {

    private FakeContract.FakeModel fakeModel;

    public FakePresenter() {
        this.fakeModel = new FakeModel();
    }

    public void getUsers() {
        fakeModel.getUsers(new OkgoStringCallback() {
            @Override
            public void onStart(Request<String, ? extends Request> request) {
                super.onStart(request);

                view.showLoading();
            }

            @Override
            public void onError(Response<String> response) {
                super.onError(response);

                view.showError(response.body());
            }

            @Override
            public void onFinish() {
                super.onFinish();

                view.hideLoading();
            }

            @Override
            public void onSuccess(Response<String> response) {
                super.onSuccess(response);

                Log.e("fake", "getUser - onSuccess");
                Log.e("fake", android.os.Process.myTid()+"");
                Log.e("fake", FakePresenter.this+"");

                String result = response.body();
                Log.d("TAG", result);

                view.showUsers(result);
            }
        });
    }

    public void getTodo() {
        fakeModel.getTodo(new OkgoStringCallback(){
            @Override
            public void onSuccess(Response<String> response) {
                super.onSuccess(response);

                Log.e("fake", "getTodp - onSuccess");
                Log.e("fake", android.os.Process.myTid()+"");
                Log.e("fake", FakePresenter.this+"");

                String result = response.body();
                Log.d("TAG", result);

                view.showTodo(result);
            }
        });
    }
}
